﻿
using Newtonsoft.Json;
using RTW.OA.Areas.Meeting.Servers;
using RTW.OA.Models;
using RTW.Utils.Utils;
using System;
using System.Collections.Generic;
using System.Web.Mvc;

namespace RTW.OA.Areas.Meeting.Controllers
{
    public class MeetingRuleController : Controller
    {
        private MeetingRuleServers meetingruleServers;

        public MeetingRuleController()
        {
            meetingruleServers = new MeetingRuleServers();
        }


        // GET: Meeting/MeetingRule
        public ActionResult Index()
        {

            return View();
        }

        // GET: Meeting/MeetingRule/Edit/5
        public ActionResult Edit(int? id)
        {
            ViewBag.MEETING_OPERATORData = meetingruleServers.GetMEETING_OPERATOR();
            var model = new meeting_rule();
            if (id != null)
            {
                ViewBag.Title = "编辑会议室管理规则表";
                model = GetModel(id.Value.ToString());
            }
            else
            {
                ViewBag.Title = "新建会议室管理规则表";
            }
            return View(model);
        }

        // POST: Meeting/MeetingRule/Edit/5
        [HttpPost]
        [ValidateInput(false)]
        public ActionResult Edit(int? id, meeting_rule model)
        {
            ViewBag.MEETING_OPERATORData = meetingruleServers.GetMEETING_OPERATOR();
            try
            {
                if (id == null || id == 0)
                {
                    meetingruleServers.Add(model);
                    ViewBag.msg = "新增会议室管理规则表信息成功！";
                    model = new meeting_rule();

                }
                else
                {
                    meetingruleServers.Update(model);
                    ViewBag.msg = "修改会议室管理规则表信息成功！";

                }
            }
            catch
            {
                ViewBag.msg = "提交出现错误！";
            }

            return View(model);
        }

        // GET: Meeting/MeetingRule/Delete/5
        public ActionResult Delete(int id)
        {
            if (id != 0)
            {
                meetingruleServers.Del(id.ToString());
                ViewBag.msg = "删除会议室管理规则表信息成功！";
            }
            return Content("");
        }


        #region //GetData
        public string GetTableJsonResult()
        {
            var list = meetingruleServers.GetData();
            return JsonConvert.SerializeObject(list);
        }

        public meeting_rule GetModel(string id)
        {
            var model = meetingruleServers.GetModelById(id);
            return model;
        }

        #endregion //GetData
    }
}